#include<stdio.h>
#include<algorithm>
using namespace std;
#define INT_MAX 0x7fffffff;
const int maxn = 100010;
int main()
{
	int N;
	scanf("%d", &N);
	int arr[maxn];
	bool isP[maxn];
	fill(isP, isP + maxn, true);
	for (int i = 0; i < N; i++) {
		scanf("%d", &arr[i]);
	}
	int lmax = 0;
	int rmin = INT_MAX;
	for (int i = 0; i < N; i++) {
		if (arr[i] < lmax) {
			isP[i] = false;
		}
		else
			lmax = arr[i];
		if (arr[N - 1 - i] > rmin) {
			isP[N-1-i] = false;
		}
		else
			rmin = arr[N - 1 - i];
	}
	int times = 0;
	for (int i = 0; i < N; i++) {
		if (isP[i])
			times++;
	}
	printf("%d\n", times);
	bool first = true;
	for (int i = 0; i < N; i++) {
		if (isP[i]) {
			if (first) {
				printf("%d", arr[i]);
				first = false;
			}
			else
				printf(" %d", arr[i]);
		}	
	}
	printf("\n");
    return 0;
}